package com.orange.notificationsummary;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;

import com.orange.notificationsummary.utils.Constants;
import com.orange.notificationsummary.utils.EventLSWidgetUtils;

public class PreferenceNotificationSettingActivity extends PreferenceActivity {

	private SharedPreferences	mSharedPreferences;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getPreferenceManager().setSharedPreferencesName(
				Constants.PREFERENCES_SERVICE_NAME);
		getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
		// Load the preferences from an XML resource
		addPreferencesFromResource(R.xml.notification_setting);
		mSharedPreferences = getSharedPreferences(
				Constants.PREFERENCES_SERVICE_NAME, MODE_WORLD_WRITEABLE);

	}

	@Override
	protected void onResume() {
		super.onResume();
		updatePreference(Constants.KEY_WIDGET_EVENT_DETAIL_VOICEMAIL,
				mSharedPreferences);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	private void updatePreference(String key,
			SharedPreferences sharedPreferences) {
		boolean isInstall = EventLSWidgetUtils.isPackageExist(this,
				Constants.PKG_VOICEMAIL);
		CheckBoxPreference Preference = (CheckBoxPreference) findPreference(key);

		if (!isInstall) {
			Preference.setEnabled(false);
		} else {
			Preference.setEnabled(true);
		}

	}

}